import { reactive, ref } from "vue"

type PsgInfoType = {
  name: string
  region: string
  date1: string
  date2: string
  delivery: boolean
  type: Array<string>
  resource: string
  desc: string
}

// 用户编辑
export const usePsgInfo = (initData: PsgInfoType = {} as any) => {
  // 初始化信息
  const psgInfo = reactive({
    name: initData.name || '',
    region: initData.region || '',
    date1: initData.date1 || '',
    date2: initData.date2 || '',
    delivery: initData.delivery || false,
    type: initData.type || [],
    resource: initData.resource || '',
    desc: initData.desc || '',
  })

  // 更新信息
  const updateInfo = () => {
    console.log('更新信息')
    setTimeout(() => {
      Object.assign(psgInfo, {name: 'xxxx'})
      console.log('更新完毕')
    }, 2000)
  }

  // 保存信息
  const savePsgInfo = () => {
    // 各种逻辑
    setTimeout(() => {
      console.log('保存', psgInfo)
    })
  }

  return {
    psgInfo,
    updateInfo,
    savePsgInfo
  }
}